﻿using System.Collections;
using System.Collections.Generic;
using Script;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class StartGame : MonoBehaviour
{
    private GameObject nodeRes;

    public int GameSpeed = 1;

    private Text speedTxt;

    private float diffTime;

    private NodeShapeSquare nodeShape { get; set; }
    
    // Start is called before the first frame update
    void Start()
    {
        InitData();
        InitUI();
    }

    void InitData()
    {
        nodeRes = Resources.Load("Prefab/NodeSquare") as GameObject;
        nodeShape = new NodeShapeSquare(nodeRes);
        
    }

    void InitUI()
    {
        speedTxt = GameObject.Find("UIViewGame/Bg/SpeedText").GetComponent<Text>();
        speedTxt.text = "Speed：" + GameSpeed;
    }

    // Update is called once per frame
    void Update()
    {
        diffTime += Time.deltaTime;
        if (diffTime >= Constant.Speed[GameSpeed - 1])
        {
            nodeShape.MoveDown();
            diffTime = diffTime - Constant.Speed[GameSpeed - 1];
        }

        if (Input.GetKeyDown(KeyCode.A))
        {
            nodeShape.MoveLeft();
        }
        
        else if (Input.GetKeyDown(KeyCode.D))
        {
            nodeShape.MoveRight();
        }
        
        else if (Input.GetKeyDown(KeyCode.S))
        {
            nodeShape.MoveDown();
        }
    }
}
